#include <stdio.h>
#include <stdint.h>
#include <sys/eventfd.h>
#include <unistd.h>
int main()
{
    // EFD_CLOEXEC -- 创建的fd，在exec之后，不会继承到子进程
    // // EFD_NONBLOCK -- 创建的fd，非阻塞
    int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
    if (efd < 0)
    {
        perror("eventfd");
        return -1;
    }
    uint64_t val = 1;
    write(efd, &val, sizeof(val));
    write(efd, &val, sizeof(val));
    // write(efd, &val, sizeof(val));

    uint64_t res = 0;
    read(efd, &res, sizeof(res));
    printf("res = %lu\n", res);
    close(efd);

    return 0;
}
